package top.laoshuzi.designpatterns.base.behavior.chain_of_responsibility;

import java.util.LinkedList;
import java.util.List;

/**
 * 过滤器链
 */
public class FilterChain implements Filter {

    private List<Filter> filterList = new LinkedList<>();


    public FilterChain addFirstFilter(Filter filter) {
        filterList.add(0, filter);
        return this;
    }

    public FilterChain addLastFilter(Filter filter) {
        filterList.add(filter);
        return this;
    }

    @Override
    public void doFilter(Target target) {
        for (Filter filter : filterList) {
            filter.doFilter(target);
        }
    }
}
